#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MINH -10001

typedef struct HNode* PtrToHNode;
struct HNode {
    int* data;
    int size;
    int capacity;
};
typedef PtrToHNode MinHeap;

MinHeap CreateHeap ( int Maxsize ) {
    MinHeap H = (MinHeap)malloc(sizeof(struct HNode));
    H->data = (int*)malloc(sizeof(int)*Maxsize);
    H->size = 0;
    H->capacity = Maxsize;
    H->data[0] = MINH;
    return H;
}

bool IsEmpty ( MinHeap H ) {
    return ( H->size == 0 );
}

bool IsFull ( MinHeap H ) {
    return ( H->size == H->capacity );
}

MinHeap Insert ( int X, MinHeap H ) {
    int i;
    if ( IsFull(H) ) {
        printf("Heap Full\n");
        return;
    }
    for ( i = ++H->size; ( i > 1 ) && ( H->data[i/2] > X ); i/=2 ) {
        H->data[i] = H->data[i/2];
    }
    H->data[i] = X;
    return H;
}

void freeHeap ( MinHeap H ) {
    free(H->data);
    // printf("Array free success\n");
    free(H);
    // printf("Heap free success\n");
    H = NULL;
}

int main () {
    MinHeap H = CreateHeap(1001);
    int i, N, M, X, output = 0;
    scanf("%d %d", &N, &M);
    for ( i = 0; i < N; i++ ) {
        scanf("%d", &X);
        Insert(X,H);
    }
    for ( i = 0; i < M; i++ ) {
        output = 0;
        scanf("%d", &X);
        for ( ; X > 0; X/=2 ) {
            if ( output == 0 ) {
                printf("%d", H->data[X]);
                output = 1;
            } else {
                printf(" %d", H->data[X]);
            }
        }
        printf("\n");
    }
    freeHeap(H);
    return 0;
}